package com.sgb.kjwl.view.ui.adapter.self.packers;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.EmploymentEntity;
import com.sgb.kjwl.model.entity.self.SelfEmploymentEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.StringUtil;

import java.util.List;

public class SelfTeamEmploymentAdapter extends BaseRecycleAdapter<EmploymentEntity> {

    public SelfTeamEmploymentAdapter(Context context, List<EmploymentEntity> data, RequestManager requestManager) {
        super(context, R.layout.item_self_packers_employment, data);
    }

    @Override
    public void convert(ItemViewHolder holder, EmploymentEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView tvWorkerInfo = holder.itemView.findViewById(R.id.tv_worker_info);
        TextView packersIndustryCategory = holder.itemView.findViewById(R.id.packers_industry_category);
        TextView tvPrice = holder.itemView.findViewById(R.id.tv_price);
        //工期
        TextView tvGq = holder.itemView.findViewById(R.id.tv_gq);

        switch (entity.getSalaryType()) {
            case 1:
                tvPrice.setText("面议");
                break;
            case 2:
                tvPrice.setText("电议");
                break;
            case 3:
                String salary = entity.getSalary();
                if (entity.getSalary().startsWith("-") || entity.getSalary().endsWith("-")){
                    salary = entity.getSalary().replace("-","");
                }
                tvPrice.setText(salary + "元/" + entity.getSalaryUnitName());
                break;
            default:
                break;
        }
        tvGq.setText(StringUtil.formatDouble(Double.valueOf(entity.getDuration())) + entity.getDurationUnitName());
        if (!TextUtils.isEmpty(entity.getIndustryName())) {
            if (!TextUtils.isEmpty(entity.getCategoryName())) {
                packersIndustryCategory.setVisibility(View.VISIBLE);
                packersIndustryCategory.setText(entity.getIndustryName() + "/" + entity.getCategoryName());
            } else {
                packersIndustryCategory.setVisibility(View.VISIBLE);
                packersIndustryCategory.setText(entity.getIndustryName());
            }
        } else {
            if (!TextUtils.isEmpty(entity.getCategoryName())) {
                packersIndustryCategory.setVisibility(View.VISIBLE);
                packersIndustryCategory.setText(entity.getCategoryName());
            } else {
                packersIndustryCategory.setText("");
                packersIndustryCategory.setVisibility(View.GONE);
            }
        }
        tvWorkerInfo.setText(String.format("%s  |  %s", entity.getContact(), entity.getContactPhone()));
        TextView tvWorkerNum = holder.itemView.findViewById(R.id.tv_worker_num);
        tvWorkerNum.setText(entity.getEmploymentNumber() + "人");
        TextView packersStart = holder.itemView.findViewById(R.id.packers_start);
        if (TextUtils.isEmpty(entity.getEmploymentStatusName()) || entity.getEmploymentStatusName().equals("招工中")) {
            packersStart.setText("招工中");
            packersStart.setBackground(context.getResources().getDrawable(R.drawable.bg_corner2_5792fd));
            packersStart.setTextColor(context.getResources().getColor(R.color.new_blue));
        } else {
            packersStart.setText("急招");
            packersStart.setBackground(context.getResources().getDrawable(R.drawable.bg_goods_info_strock_red_line4));
            packersStart.setTextColor(context.getResources().getColor(R.color.new_org2));
        }

        Button editView = holder.getItem().findViewById(R.id.btn_edit);
        Button delView = holder.getItem().findViewById(R.id.btn_delete);
        editView.setOnClickListener(v -> {
            if (itemCallBack != null) {
                itemCallBack.edit(entity.getNo());
            }
        });
        delView.setOnClickListener(v -> {
            if (itemCallBack != null) {
                itemCallBack.del(entity.getNo());
            }
        });
    }

    private ItemCallBack itemCallBack;

    public void setItemCallBack(ItemCallBack itemCallBack) {
        this.itemCallBack = itemCallBack;
    }

    public interface ItemCallBack {
        void del(String no);

        void edit(String no);
    }
}
